<?php
include 'checkLogin.php';
include 'db/li.php';

@$pid = $_REQUEST['pid'];
@$img = $_FILES['file'];
@$id = $_REQUEST['id'];

@$name = $_REQUEST['name'];
@$value = $_REQUEST['value'];
@$pk = $_REQUEST['pk'];


if(!empty($pid)){			//修改图片
	move_uploaded_file($img['tmp_name'],'img/worker/'.$img['name']);
	
	@$flog = dbUpdate('update worker set imgUrl=:img where id=:id',array('img'=>$img['name'],'id'=>$pid));
	if(!$flog){
		die(json_encode(array('status'=>false,'info'=>'修改失败','img'=>$img,'pid'=>$pid)));
	}
	echo json_encode(array('status'=>true));
}
if(!empty($id)){		//刷新图片
	@$img = dbSelect('select imgUrl from worker where id=:id',array('id'=>$id));
	if(empty($img)){
		die(json_encode(array('status'=>false,'info'=>'获取图片路径失败')));
	}
	echo json_encode(array('status'=>true,'src'=>$img['imgUrl']));
}
if(!empty($name) && !empty($value) && !empty($pk)){			//改基本信息
	if($name == "role"){
		@$flog = dbUpdate("update role set name=:value where id=:id",array('value'=>$value,'id'=>$pk));
	}else{
		@$flog = dbUpdate("update worker set $name=:value where id=:id",array('value'=>$value,'id'=>$pk));
	}
	if(!$flog){
		header('HTTP/1.1 409');
		die;
	}
	
	echo json_encode(array('status'=>true));
}